import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';

export default function beforeFormEdit(areaCode, key) {
    const {orgVal, form} = this.props;
    const that = this;
    let postData = {
        pk_org: orgVal.refpk,
        key,
        model: form.getAllFormValue(areaCode)
    };

    return proFetch({
        url: '/nccloud/hrtrn/partrds/PartRdsAddBeforeEditAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success && res.data.editable) {
                if (res.data.refParam) {
                    let meta = that.props.meta.getMeta();
                    let editItem = meta[areaCode].items.find(item => item.attrcode === key);
                    editItem.queryCondition = function () {
                        return res.data.refParam
                    };
                    that.props.meta.setMeta(meta);
                }
                return true;
            }
        });
}
